/**
 * Created by Administrator on 2017/2/7.
 */
var Param = {
  Version:"0.0.1",
  Platform:"WechatApp",
  AppSecret:"86c42d9dc49e31ded1936a71854c0fdfb67b8505"
}

import store from './../../vuex/store'
const commit =  store.dispatch || store.commit

function getVersion(){
    return Param.Version;
}

function getPlatform(){
    return Param.Platform;
}

function getAppSecret(){
    return Param.AppSecret;
}

function showToast(data, that) {
   that.$vux.toast.show({
      text: data,
      type: 'text',
      width: '11em',
      time: '1000',
      onShow () {},
      onHide () {}
    }); 
}

function closeLoading() {
    commit('UPDATE_LOADING', false)
}


function getFloorData() {
    var floor = new Array();
    var floorItems = new Array();
    for(var i = 1; i < 100; i ++) {
        var item = i + '楼';
        floorItems.push(item);
    }
    floor.push(floorItems);
    return floor;
}

function toDecimal2(x) {
    var f = parseFloat(x);
    if (isNaN(f)) {
        return false;
    }
    var f = Math.round(x * 100) / 100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + 2) {
        s += '0';
    }
    return s;
}

function getCurDay() {
    var date = new Date();
    var year = date.getFullYear();  
    var month = date.getMonth() + 1;  
    if (month < 10) month = "0" + month;  
    var day = date.getDate(); 
    if (day < 10) day = "0" + day;  
    return  (year + "-" + month + "-" + day)
}

function getNewDay(dateTemp, days) {  
    var dateTemp = dateTemp.split("-");
    var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]); //转换为MM-DD-YYYY格式    
    var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);
    var rDate = new Date(millSeconds);
    var year = rDate.getFullYear();
    var month = rDate.getMonth() + 1;  
    if (month < 10) month = "0" + month;  
    var date = rDate.getDate();  
    if (date < 10) date = "0" + date;  
    return (year + "-" + month + "-" + date);  
} 

module.exports = {
    getVersion: getVersion,
    getPlatform: getPlatform,
    getAppSecret: getAppSecret,
    showToast: showToast,
    closeLoading: closeLoading,
    getFloorData: getFloorData,
    toDecimal2: toDecimal2,
    getNewDay: getNewDay,
    getCurDay: getCurDay
}